<?Lassoscript
// Last modified 5/19/09 by Eric Landmann

// CHANGE NOTES
// 4/17/09
// Version 1.0
// 5/19/09
// Changed a few hrefs to make not root-relevant

// FUNCTIONALITY
// This code will delete the photo on disk for a particular member

// DEVELOPER'S NOTES
// The assumption is that the filename will be named on disk the same as the MemberID
// Therefore, no database entry is needed as we know the MemberID from the login
// This page does not display anything, it is a process-only page with a redirect to m_update.lasso
Include:'siteconfig.lasso';

// Start the Session
Include:($svLibsPath)'sessions.inc'; 

// Var:'svDebug' = 'Y';

// Setting variables
Var:'vMember' = (Action_Param:'Member');
Var:'vError' = (Action_Param:'Error');
Var:'vOption' = (Action_Param:'Option');

// Checking if ID submit matches logged-in member's ID
// If not, error with error 5012 "Access Denied"
// This also doubles as a login check, as if the svMemberID is nothing, they are not logged in
If: (Var:'svMemberID') != (Var:'vMember');
	Var:'vError' = '5012';
Else;
	
	// Delete the File
	Var:'PhotoName' = ('member/'(Var:'svMemberID')'.jpg');
	Debug;
		'PhotoName = ' $PhotoName '<br>\n';
	/Debug;

	If: (File_Exists:($PhotoName));

		Inline: -Action='nothing', -Username=$svSiteUsername, -Password=$svSitePassword;

			File_Delete:($PhotoName);

			// If delete failed, output error 5063, "File Deletion Failed"
			// If it was successful, output error 5062, "File Deletion Successful"
			If: ((File_CurrentError: -ErrorCode) != '0') || ((Error_CurrentError: -ErrorCode) != '0');
				Var:'vError' = '5063';
				Var:'vOption' = (File_CurrentError);
			Else;
				Var:'vError' = '5062';
			/If;
			Debug;
				'249: vError = ' $vError '<br>\r';
				'249: vOption = ' $vOption '<br>\r';
			/Debug;
	
		/Inline;

		// Otherwise, we don't know what's going on, error 9000
		Else;
			Var:'vError' = '9000';
	
		/If;

/If;

// Redirect to Member Profile page with error message
Var:'URL' = ('m_update.lasso?Error='($vError)'&Option='($vOption));
If: $svDebug == 'Y';
	Debug;
		'61: URL = ' $URL '<br>';
	/Debug;
Else;
	Redirect_URL: $URL;
/If;


?>